#include "GLHelper/BrendMode.hpp"
#include <Windows.h>
#include <gl/GL.h>
#include <cassert>
namespace GLHelper{
typedef void (APIENTRY *PFNGLBLENDEQUATIONEXT)(GLenum op);
static PFNGLBLENDEQUATIONEXT glBlendEquationEXT = 0;

const GLenum GL_FUNC_ADD = 0x8006;
const GLenum GL_FUNC_REVERSE_SUBTRACT = 0x800B;

void ApplyBrendMode(BrendMode BM)
{
	if(glBlendEquationEXT == 0)
	{
		glBlendEquationEXT = (PFNGLBLENDEQUATIONEXT)wglGetProcAddress("glBlendEquationEXT");
		assert( glBlendEquationEXT );
	}

	switch(BM)
	{
	case BLEND_OPAQUE:
		glDisable(GL_BLEND);
		break;
	case BLEND_LINEAR:
		glEnable(GL_BLEND);
		glBlendEquationEXT(GL_FUNC_ADD);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		break;
	case BLEND_ADDITIVE:
		glEnable(GL_BLEND);
		glBlendEquationEXT(GL_FUNC_ADD);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE);
		break;
	case BLEND_SUBSTRACTIVE:
		glEnable(GL_BLEND);
		glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE);
		break;
	}
}
}//GLHelper